<?php
declare(strict_types=1);


namespace App\Fastapp\Mapper;

use App\Fastapp\Model\AccountEventLog;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 事件记录列表Mapper类
 */
class FastappAccountEventLogMapper extends AbstractMapper
{
    /**
     * @var AccountEventLog
     */
    public $model;

    public function assignModel()
    {
        $this->model = AccountEventLog::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        // 用户ID
        if (isset($params['user_id']) && filled($params['user_id'])) {
            $query->where('user_id', '=', $params['user_id']);
        }

        // 事件
        if (isset($params['event']) && filled($params['event'])) {
            $query->where('event', '=', $params['event']);
        }
        return $query->orderByDesc('id');
    }
}